import http from './interface'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */

// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const test = (data) => {
	/* http.config.baseUrl = "http://localhost:8080/api/"
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		}
	} */
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....')
		//判断返回状态 执行相应操作
		return response;
	}
	return http.request({
		baseUrl: 'https://unidemo.dcloud.net.cn/',
		url: 'ajax/echo/text?name=uni-app',
		dataType: 'text',
		data,
	})
}

// 轮播图
export const banner = (data) => {
	return http.request({
		url: '/banner/36kr',
		method: 'GET',
		data,
		// handle:true
	})
}

// 登录
export const pcLogin = (data) => {
	return http.request({
		url: '/login/pcLogin',
		method: 'POST',
		data,
		// handle:true
	})
}

// 获取首页商品图片
export const getGoodTypeInfo = (data) => {
	return http.request({
		url: '/user/getGoodTypeInfo',
		method: 'GET',
		data,
		// handle:true
	})
}

// 获取首页详情商品图片合集
export const getGoodsPhotoInfo = (data) => {
	return http.request({
		url: '/user/getGoodsPhotoInfo',
		method: 'GET',
		data,
		// handle:true
	})
}

// 获取首页详情商品产品合集
export const getGoodsProductsInfo = (data) => {
	return http.request({
		url: '/user/getGoodsProductsInfo',
		method: 'GET',
		data,
		// handle:true
	})
}

// 获取首页详情商品装修项目合集
export const getGoodsDecoratitemsInfo = (data) => {
	return http.request({
		url: '/user/getGoodsDecoratitemsInfo',
		method: 'GET',
		data,
		// handle:true
	})
}

// 用户提交信息，
export const register = (data) => {
	return http.request({
		url: '/user/register',
		method: 'POST',
		data,
		// handle:true
	})
}

// 用户点击链接进行相应的扣费
export const linkUserDeduction = (data) => {
	return http.request({
		url: '/user/linkUserDeduction',
		method: 'POST',
		data,
		// handle:true
	})
}

// 链接用户注册
export const linkRegister = (data) => {
	return http.request({
		url: '/user/linkRegister',
		method: 'POST',
		data,
		// handle:true
	})
}

// 链接用户登录
export const login = (data) => {
	return http.request({
		url: '/account/login',
		method: 'POST',
		data,
		// handle:true
	})
}

// 链接用户获取访问记录扣费情况
export const getDeductionRecords = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/linkUser/getDeductionRecords',
		method: 'GET',
		data,
		// handle:true
	})
}

// 链接用户添加店铺地址
export const AddShopAddress = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/linkUser/AddShopAddress',
		method: 'POST',
		data,
		// handle:true
	})
}

// 获取链接用户店铺地址
export const getUserShopAddress = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/linkUser/getUserShopAddress',
		method: 'POST',
		data,
		// handle:true
	})
}

// 修改个人信息店铺名称
export const updateShopName = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/linkUser/updateShopName',
		method: 'POST',
		data,
		// handle:true
	})
}

// 注册获取验证码
export const getSMSCode = (data) => {
	return http.request({
		url: '/user/getSMSCode',
		method: 'POST',
		data,
		// handle:true
	})
}

// 连接用户重置密码
export const updateUserPwd = (data) => {
	return http.request({
		url: '/user/updateUserPwd',
		method: 'GET',
		data,
		// handle:true
	})
}

// 业主查询房源信息
export const getHouseInfos = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/houseInfo/getHouseInfos',
		method: 'POST',
		data,
		// handle:true
	})
}

// 添加验收信息
export const addAcceptanceInfo = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/acceptanceInfo/addAcceptanceInfo',
		method: 'POST',
		data,
		// handle:true
	})
}

// 工人确认验收信息
export const acceptanceConfirm = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/acceptanceInfo/acceptanceConfirm',
		method: 'POST',
		data,
		// handle:true
	})
}

// 工长或者监理确认验收信息
export const updateHouseInfo = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/houseInfo/updateHouseInfo',
		method: 'POST',
		data,
		// handle:true
	})
}

// 获取验收信息
export const getAcceptanceList = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/acceptanceInfo/getAcceptanceList',
		method: 'POST',
		data,
		// handle:true
	})
}

// 获取验收信息
export const updateAcceptanceInfo = (data) => {
  http.interceptor.request = (config) => {
  	config.header = {
  		Authorization: 'Bearer ' + uni.getStorageSync('userInfo').token
  	}
  }
	return http.request({
		url: '/acceptanceInfo/updateAcceptanceInfo',
		method: 'POST',
		data,
		// handle:true
	})
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	test,
	banner,
	pcLogin,
	getGoodTypeInfo,
	getGoodsPhotoInfo,
	getGoodsProductsInfo,
	getGoodsDecoratitemsInfo,
	register,
	linkUserDeduction,
	linkRegister,
	login,
	getDeductionRecords,
	AddShopAddress,
	getUserShopAddress,
	updateShopName,
	getSMSCode,
	updateUserPwd,
	getHouseInfos,
	addAcceptanceInfo,
	updateHouseInfo,
	getAcceptanceList,
	updateAcceptanceInfo,
	acceptanceConfirm
}
